home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DRIVES.SWG / 0054_Detecting RAM Disks.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-02  |  4KB  |  104 lines

  1. {
  2. Desclin Jean <desclinj@ulb.ac.be>
  3.  
  4.  a few days ago (sorry, I didn't write down the name of the person
  5.  who posted the question :-(), someone asked how one could
  6.  identify a drive as a ramdisk.
  7.  Below is a solution, which I submit with the hope that someone
  8.  else could show how to improve on it, since it is not 'fail-safe'.
  9.  Here it comes...
  10.  
  11. Modified after Michael Tischer: Turbo Pascal 6 System Programming
  12. ABACUS Publisher Grand Rapids, MI 49512  1991 ISBN 1-55755-124-3
  13. I had to write the procedure Getdrives twice in order to take into
  14. account the changes in the DPB structure which occurred from DOS
  15. 4.0 onwards. Mostly, Ramdisks have only one File Allocation Table,
  16. whereas other drive types have two. That's what a procedure such
  17. as GetDiskClass of TurboPower Object Professional (usual disclaimer
  18. here ;-)) uses to decide whether the drive is a ramdisk or not. BUT
  19. BEWARE! This is not necessarily so! Norton mentions, in his 'disk
  20. companion', that depending on the device driver of the ramdisk, one
  21. or two FATS may be implemented. I could verify this on 'STACKED'
  22. ramdisks: they have two FATS, whereas only one FAT is present after
  23. 'unSTACKING' :-(. Thus, the solution below is somewhat shaky.
  24. }
  25.  
  26.  
  27. program idramdsk;
  28. uses
  29.   Dos;
  30.  
  31. var
  32.   ver : byte;
  33.  
  34. procedure GetDrives1;
  35. type
  36.   DPBPTR    = ^DPB;                 { pointer to a DOS Parameter Block }
  37.   DPBPTRPTR = ^DPBPTR;              { pointer to a pointer to a DPB }
  38.   DPB       = record                { recreation of a DOS Parameter Block }
  39.     Code   : byte;                  { drive code (0=A, 1=B etc. }
  40.     dummy1 : array [1..$07] of byte;{irrelevant bytes}
  41.     FatNb  : byte;                  {Number of File Allocation Tables }
  42.     dummy2 : array [9..$17] of byte;{irrelevant bytes}
  43.     Next   : DPBPTR;                { pointer to next DPB }
  44.   end;                              { xxxx:FFFF marks last DPB }
  45.  
  46. var
  47.   Regs     : Registers;             { register for interrupt call }
  48.   CurrDpbP : DPBPTR;                { pointer to DPBs in memory }
  49.  
  50. begin
  51.   {-- get pointer to first DPB ------------------------------------}
  52.   Regs.AH := $52; {function $52 returns ptr to DOS Information Block }
  53.   MsDos(Regs);    {that's an UNDOCUMENTED DOS function !             }
  54.   CurrDpbP := DPBPTRPTR(ptr(Regs.ES, Regs.BX))^;
  55.  
  56.   {-- follow the chain of DPBs--------------------------------------}
  57.   repeat
  58.     writeln(chr(ord('A') + CurrDpbP^.Code),     {display device code }
  59.               ':(FATS: ', CurrDpbP^.FatNb,')'); {and number of FATs  }
  60.  
  61.     CurrDpbP := CurrDpbP^.Next;   { set pointer to next DPB        }
  62.   until (Ofs(CurrDpbP^) = $FFFF);  { until last DPB is reached }
  63. end;
  64.  
  65. procedure GetDrives2;
  66. type
  67.   DPBPTR    = ^DPB;                 { pointer to a DOS Parameter Block }
  68.   DPBPTRPTR = ^DPBPTR;              { pointer to a pointer to a DPB }
  69.   DPB       = record                { recreation of a DOS Parameter Block }
  70.     Code   : byte;                  { drive code (0=A, 1=B etc. }
  71.     dummy1 : array [1..$07] of byte;{irrelevant bytes}
  72.     FatNb  : byte;                  { Number of File Allocation Tables}
  73.     dummy2 : array [9..$18] of byte;{irrelevant bytes}
  74.     Next   : DPBPTR;                { pointer to next DPB }
  75.   end;                              { xxxx:FFFF marks last DPB }
  76.  
  77. var
  78.   Regs     : Registers;             { register for interrupt call }
  79.   CurrDpbP : DPBPTR;                { pointer to DPBs in memory }
  80.  
  81. begin
  82.   {-- get pointer to first DPB-------------------------------------}
  83.   Regs.AH := $52; {function $52 returns ptr to Dos Information Block }
  84.   MsDos(Regs);    {that's an UNDOCUMENTED DOS function !             }
  85.   CurrDpbP := DPBPTRPTR(ptr(Regs.ES, Regs.BX))^;
  86.  
  87.   {-- follow the chain of DPBs -------------------------------------}
  88.   repeat
  89.     {output device letter and number of FATs (1 for RAM disks)   }
  90.     writeln(chr(ord('A') + CurrDpbP^.Code), ':(FATS: ', CurrDpbP^.FatNb, ')');
  91.     CurrDpbP := CurrDpbP^.Next;    { set pointer to next DPB        }
  92.   until (Ofs(CurrDpbP^) = $FFFF);  { until last DPB is reached }
  93. end;
  94.  
  95. begin
  96.   ver := Lo(DosVersion);
  97.   writeln(#13#10'Installed drives: '#13#10);
  98.   if ver < 4 then
  99.     GetDrives1
  100.   else
  101.     GetDrives2
  102. end.
  103.  
  104.